package _17_剑指Offer;

public class _62_剑指Offer圆圈中最后剩下的数字 {

    public int lastRemaining(int n, int m) {
        // 每剔除一位后，胜利者编号退后m
        int x = 0;
        for (int i = 2; i <= n; i++) {
            x = (x + m) % i;
        }
        return x;
    }

    // 迭代
    public int lastRemaining1(int n, int m) {
        return n == 1? 0: (lastRemaining1(n - 1, m) + m) % n;
    }

}
